<?php
namespace app\interfaces\controller;

use app\interfaces\model\Shop as ShopModel;
use app\interfaces\model\ShopType as ShopTypeModel;
use app\interfaces\model\Ad as AdModel;
use think\Request;


class DiscoverShop
{

    /*
     * 用户端 - 发现好店 - 商品列表
     * @param  string $type_id 唯一标示
     */
    public function goods_list()
    {

        // 获取参数
        $inquire = Request::instance()->param();
		
		$pagenum = isset($inquire['pagenum']) ? $inquire['pagenum'] : '1';

        // 搜索条件
       	 $condition['status'] = ['eq', 1];
 		 $condition['recommend'] = ['eq', 1];

        $condition['valid_time'] = [['gt', time()], ['eq', ''], 'or'];

        // 条件
        if (!empty($inquire['type_id'])) $condition['type_id'] = ['eq', $inquire['type_id']];

        $model = new ShopModel();
        $result = $model->where($condition)
            ->field('member_id,title,banner,description,type')
            ->order(['recommend' => 'asc', 'sort' => 'desc', 'create_time' => 'desc'])
            ->paginate(5, false, ['query' => $inquire,'page' => $pagenum]);

        foreach ($result as $key => &$value) {
            $value->goods;
        }

        // 广告
        $ad_find = AdModel::where(['parenTid' => '17'])
            ->field('picUrl,linkUrl,skip_type')
            ->find();

        return ['code' => 200, 'message' => '成功', 'data' => $result, 'ad_find' => $ad_find];


    }

    /*
     * 用户端 - 发现好店 - 分类列表
     */
    public function type_list()
    {

        $result = (new ShopTypeModel)->where('status',1)->field('id,title,sort,status')->select();

        return ['code' => 200, 'message' => '成功', 'data' => $result];


    }

}
